<template>
  <PageContainer>
    <view class="rich-details">
      <Header :title="title || '消息详情'" :is-box-shadow="false" />
      <!-- <view v-if="title" class="title">{{ title }}</view> -->
      <TRichText :content="content" />
    </view>
  </PageContainer>
</template>

<script setup lang="ts">
  import PageContainer from '@/components/PageContainer/index.vue';
  import Header from '@/components/Header/index.vue';
  import { ref, unref } from 'vue';
  import { onLoad } from '@/router';
  import TRichText from '@/components/TRichText/index.vue';
  import { onShareAppMessage } from '@dcloudio/uni-app';
  import { useAppStoreWithOut } from '@/store/modules/app';
  import { getCustomePageContent } from '@/api/admin';
  import { useAppShare } from '@/hooks/core/useAppShare';

  const id = ref<string | number | undefined>(undefined);
  const title = ref<string>();
  const content = ref<string>();
  const { setWxSharePath } = useAppShare();

  const shareOp = ref();
  onLoad<'RichDetails'>(async (op) => {
    shareOp.value = op;
    id.value = op.id;
    getDetails();
  });

  function getDetails() {
    /** 获取消息-自定义内容 */
    getCustomePageContent(unref(id) as string).then((_r) => {
      const { messageTitle, customPage } = _r;
      title.value = messageTitle;
      content.value = customPage;
    });
  }

  const { globalConfig } = useAppStoreWithOut();
  onShareAppMessage(() => ({
    imageUrl: globalConfig?.comShareOptions.shareImg,
    path: setWxSharePath({ name: 'messageCustomPage', options: shareOp.value }),
    title: title.value || globalConfig?.comShareOptions.shareTitle,
  }));
</script>

<style lang="scss" scoped>
  .rich-details {
    padding: 10rpx 40rpx;
    min-height: 100vh;
    background-color: #fff;
    .title {
      font-weight: 600;
      font-size: 40rpx;
      text-align: center;
      margin: 40rpx 0;
    }
  }
</style>
